package kr.co.sharping.Fragment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

public class TimeLineListFragment extends NetworkListFragment {

	private mAdapter adapter;
	private ArrayList<TimeLineItem> items;
	
	@Override
	public ArrayAdapter<?> dataParssingAdapter(String result, Gson gson) {
		
		ArrayList<TimeLineItem> list = gson.fromJson(result, new TypeToken<TimeLineItem>(){}.getType());
		
		if (adapter == null) {
			adapter = new mAdapter(getActivity(), 0, list);
			items = list;
		} else {
			for (int i = 0; i < list.size(); i++) {
				items.add(list.get(i));
			}
		}
		
		return adapter;
	}

	@Override
	public View setEmptyListView() {
		return null;
	}

	@Override
	public Intent onListItemClick(int ItemPosition) {
		
		// Intent intent = new Intent(getActivity(), DetailTimeLineItem.class);
		// intent.putExtra("item", adapter.getItem(ItemPosition));
		
		return null;
	}

	@Override
	public void setListViewOption(ListView baseList,
			PullToRefreshListView pullToRefreshListView) {
		super.setListViewOption(baseList, pullToRefreshListView);
		
	}
	
	public class TimeLineItem implements Serializable{

		private static final long serialVersionUID = 5266139762739439731L;
		int position;
		
	}
	
	private class mAdapter extends ArrayAdapter<TimeLineItem> {

		public mAdapter(Context context, int resource,
				List<TimeLineItem> objects) {
			super(context, resource, objects);
			// TODO Auto-generated constructor stub
		}
		
		@Override
		public long getItemId(int position) {
			return getItem(position).position;
		}
	}
}
